#include <iostream>
#include <algorithm>

using namespace std;

const int N = 5010;

typedef pair<int, int> PII;

int n;
int f[N];
PII a[N];

int main() {
    cin >> n;
    for (int i = 0; i < n; ++ i) scanf("%d%d", &a[i].first, &a[i].second);
    sort(a, a + n);
    
    int res = 0;
    for (int i = 0; i < n; ++ i) {
        for (int j = 0; j < i; ++ j)
            if (a[i].second > a[j].second) f[i] = max(f[i], f[j] + 1);
        res = max(res, f[i]);
    }
    
    cout << res + 1 << endl;
    
    return 0;
}